package cn.tedu.car.backend.station.controller;

import cn.tedu.car.backend.base.response.JsonResult;
import cn.tedu.car.backend.station.pojo.dto.StationQuery;
import cn.tedu.car.backend.station.pojo.dto.StationSaveParam;
import cn.tedu.car.backend.station.pojo.dto.StationUpdateParam;
import cn.tedu.car.backend.station.pojo.vo.StationVO;
import cn.tedu.car.backend.station.service.StationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "站点操作接口")
@RequestMapping("/station/")
public class StationController {
    @Autowired
    private StationService stationService;

    @PostMapping("add")
    @ApiOperation("新增站点")
    public JsonResult addStation(StationSaveParam stationSaveParam){
        log.debug("新增站点输入参数：stationSaveParam:{}",stationSaveParam);
        stationService.addStation(stationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("load")
    @ApiOperation("获取站点信息")
    public JsonResult loadStation(StationQuery stationQuery){
        log.debug("站点查询输入参数：stationQuery:{}",stationQuery);
        List<StationVO> stationList=stationService.loadStation(stationQuery);
        log.debug("返回站点参数：stationList：{}",stationList);
        return JsonResult.ok(stationList);
    }
    @PostMapping("update")
    @ApiOperation("更新站点信息")
    public JsonResult updateStation(StationUpdateParam stationUpdateParam){
        log.debug("站点更新输入参数:stationUpdateParam{}",stationUpdateParam);
        stationService.updateStation(stationUpdateParam);
        log.debug("已更新站点数据数据");
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    @ApiOperation("删除站点")
    public JsonResult deleteStation(@PathVariable Long id){
        log.debug("删除站点入参：{}",id);
        stationService.deleteStation(id);
        return JsonResult.ok();
    }

}
